<?php

namespace App\Models;

class Adsense extends Base
{
    protected $table = 'adsenses';

    const STATUS_1 = 1;
    const STATUS_2 = 2;

    const STATUS_TEXT = [
        self::STATUS_1 => '<span class="el-tag">正常</span>',
        self::STATUS_2 => '<span class="el-tag el-tag--danger">锁定</span>',
    ];

    const GROUP_1 = 1;
    const GROUP_2 = 2;
    const GROUP_TEXT = [
        self::GROUP_1 => '轮播',
        self::GROUP_2 => '横幅',
    ];

    protected $fillable = [
        'id','group','width','height','materiel','status','created_at','updated_at',
        //materiel : title thumb  brief  link  target
    ];

    protected $casts = [
        'materiel' => 'array'
    ];

    protected function list($params = [], $fields = ['*']){
        return $this->select($fields)
            ->where(function ($query) use ($params) {
                if(isset($params['status']) && $params['status']) {
                    $query ->where('status',$params['status']);
                }
            })->orderBy('id', 'desc')
            ->paginate(config('setting.limit'));
    }

}
